package com.wealth.scsj.b_app.view.activity;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.wealth.scsj.b_app.R;
import com.wealth.scsj.b_app.base.AboutAddNewGoodsBase;
import com.wealth.scsj.b_app.bean.AllClassfyBean;
import com.wealth.scsj.b_app.bean.GoodsDetailBean;
import com.wealth.scsj.b_app.bean.QueryAllMarksBean;
import com.wealth.scsj.b_app.bean.QueryAllTerraceBean;
import com.wealth.scsj.b_app.bean.QueryShopBrandBean;
import com.wealth.scsj.b_app.presenter.AboutAddNewShopsPresenter;

import es.dmoral.toasty.Toasty;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 新增商品
 *
 * @author qxp
 */
public class AddCommodityPageActivity extends BaseActivity implements AboutAddNewGoodsBase.IView {

    private AboutAddNewShopsPresenter presenter;
    private ImageView mBtnBack;
    private TextView mTvTopTittle;
    private TextView mTvTopRight;
    /**
     * 你是谁
     */
    private EditText mProductNameEt;
    private RelativeLayout mProductNameRl;
    /**
     * 你是谁
     */
    private EditText mCommodityClassificationBusinessValueEt;
    private RelativeLayout mCommodityClassificationBusinessRl;
    /**
     * 你是谁
     */
    private EditText mCommodityClassificationPlatformValueEt;
    private RelativeLayout mCommodityClassificationPlatformRl;
    /**
     * 你是谁
     */
    private EditText mCommodityBrandValueEt;
    private RelativeLayout mCommodityBrandRl;
    private ImageView mBarCodeAddIv;
    /**
     * 请输入条形码
     */
    private TextView mBarCodeValueTv;
    private RelativeLayout mBarCodeRl;
    /**
     * 你是谁
     */
    private EditText mMeasureUnitValueEt;
    private RelativeLayout mMeasureUnitRl;
    /**
     * 你是谁
     */
    private EditText mCommodityTagValueEt;
    private RelativeLayout mCommodityTagRl;
    /**
     * 请输入商品规格
     */
    private EditText mCommoditySpecificationsValueEt;
    private RelativeLayout mCommoditySpecificationsRl;
    /**
     * 请输入原产地
     */
    private EditText mCountryOfOriginValueEt;
    private RelativeLayout mCountryOfOriginRl;
    /**
     * 请输入重量
     */
    private EditText mWeightValueEt;
    private RelativeLayout mWeightRl;
    /**
     * 请输入仓库地址
     */
    private EditText mWarehouseAddressValueEt;
    private RelativeLayout mWarehouseAddressRl;
    /**
     * 是
     */
    private RadioButton mConfirmRb;
    /**
     * 否
     */
    private RadioButton mCancelRb;
    private RadioGroup mConfirmOrCancelRg;
    private RelativeLayout mImportOrExportRl;
    /**
     * 是
     */
    private RadioButton mConfirmInvoiceRb;
    /**
     * 否
     */
    private RadioButton mCancelInvoiceRb;
    private RelativeLayout mHaveInvoiceRl;
    /**
     * 请输入库存数量
     */
    private EditText mInventoryQuantityValueEt;
    private RelativeLayout mInventoryQuantityRl;
    /**
     * 请输入报警数量
     */
    private EditText mAlarmNumValueEt;
    private RelativeLayout mAlarmNumRl;
    /**
     * 请输入市场价
     */
    private EditText mMarketValueEt;
    private RelativeLayout mMarketValueRl;
    /**
     * 请输入商品原价
     */
    private EditText mOriginalPriceValueEt;
    private RelativeLayout mOriginalPriceRl;
    /**
     * 请输入商品原价
     */
    private EditText mActiveTypeValueEt;
    private RelativeLayout mActionTypeRl;
    /**
     * 请输入限购数量
     */
    private EditText mLimitPurchaseQuantityEt;
    private RelativeLayout mLimitPurchaseQuantityRl;
    /**
     * 请输入销售价格
     */
    private EditText mSellingPriceValueEt;
    private RelativeLayout mSellingPriceRl;
    /**
     * 0
     */
    private EditText mCommissionSettingValueEt;
    private RelativeLayout mCommissionSettingRl;
    private LinearLayout mAddProductMainPictureLl;
    private LinearLayout mAddProductOtherPictureLl1;
    private LinearLayout mAddProductOtherPictureLl2;
    private LinearLayout mAddProductOtherPictureLl3;
    /**
     * 请详细描述问题和意见
     */
    private TextView mProposalTv;
    /**
     * 请输入您的店铺公告详细信息~
     */
    private EditText mShopNoticeEt;
    private RelativeLayout mShopNoticeRl;
    private LinearLayout mAddContentMainPictureLl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_commodity_page);
        initView();

        presenter = new AboutAddNewShopsPresenter(this);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("descHeightFrameCapture", "10");
        jsonObject.put("descWidthFrameCapture", "10");

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("id", "be281121-7dc9-11e8-afb7-70106fb15682");
        jsonObject.put("goods", jsonObject1);

        jsonObject.put("masterHeightFrameCapture", "20");
        jsonObject.put("masterWidthFrameCapture", "20");
        jsonObject.put("secondaryHeightFrameCapture", "15");
        jsonObject.put("secondaryWidthFrameCapture", "15");
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), jsonObject.toString());

        presenter.deliberAllGoodsData(body);
    }

    @Override
    protected void createView(Bundle savedInstanceState) {

    }

    @Override
    protected void initView() {

        mBtnBack = (ImageView) findViewById(R.id.btn_back);
        mTvTopTittle = (TextView) findViewById(R.id.tv_top_tittle);
        mTvTopRight = (TextView) findViewById(R.id.tv_top_right);
        mProductNameEt = (EditText) findViewById(R.id.product_name_et);
        mProductNameRl = (RelativeLayout) findViewById(R.id.product_name_rl);
        mCommodityClassificationBusinessValueEt = (EditText) findViewById(R.id.commodity_classification_business_value_et);
        mCommodityClassificationBusinessRl = (RelativeLayout) findViewById(R.id.commodity_classification_business_rl);
        mCommodityClassificationPlatformValueEt = (EditText) findViewById(R.id.commodity_classification_platform_value_et);
        mCommodityClassificationPlatformRl = (RelativeLayout) findViewById(R.id.commodity_classification_platform_rl);
        mCommodityBrandValueEt = (EditText) findViewById(R.id.commodity_brand_value_et);
        mCommodityBrandRl = (RelativeLayout) findViewById(R.id.commodity_brand_rl);
        mBarCodeAddIv = (ImageView) findViewById(R.id.bar_code_add_iv);
        mBarCodeValueTv = (TextView) findViewById(R.id.bar_code_value_tv);
        mBarCodeRl = (RelativeLayout) findViewById(R.id.bar_code_rl);
        mMeasureUnitValueEt = (EditText) findViewById(R.id.measure_unit_value_et);
        mMeasureUnitRl = (RelativeLayout) findViewById(R.id.measure_unit_rl);
        mCommodityTagValueEt = (EditText) findViewById(R.id.commodity_tag_value_et);
        mCommodityTagRl = (RelativeLayout) findViewById(R.id.commodity_tag_rl);
        mCommoditySpecificationsValueEt = (EditText) findViewById(R.id.commodity_specifications_value_et);
        mCommoditySpecificationsRl = (RelativeLayout) findViewById(R.id.commodity_specifications_rl);
        mCountryOfOriginValueEt = (EditText) findViewById(R.id.country_of_origin_value_et);
        mCountryOfOriginRl = (RelativeLayout) findViewById(R.id.country_of_origin_rl);
        mWeightValueEt = (EditText) findViewById(R.id.weight_value_et);
        mWeightRl = (RelativeLayout) findViewById(R.id.weight_rl);
        mWarehouseAddressValueEt = (EditText) findViewById(R.id.warehouse_address_value_et);
        mWarehouseAddressRl = (RelativeLayout) findViewById(R.id.warehouse_address_rl);
        mConfirmRb = (RadioButton) findViewById(R.id.confirm_rb);
        mCancelRb = (RadioButton) findViewById(R.id.cancel_rb);
        mConfirmOrCancelRg = (RadioGroup) findViewById(R.id.confirm_or_cancel_rg);
        mImportOrExportRl = (RelativeLayout) findViewById(R.id.import_or_export_rl);
        mConfirmInvoiceRb = (RadioButton) findViewById(R.id.confirm_invoice_rb);
        mCancelInvoiceRb = (RadioButton) findViewById(R.id.cancel_invoice_rb);
        mHaveInvoiceRl = (RelativeLayout) findViewById(R.id.have_invoice_rl);
        mInventoryQuantityValueEt = (EditText) findViewById(R.id.inventory_quantity_value_et);
        mInventoryQuantityRl = (RelativeLayout) findViewById(R.id.inventory_quantity_rl);
        mAlarmNumValueEt = (EditText) findViewById(R.id.alarm_num_value_et);
        mAlarmNumRl = (RelativeLayout) findViewById(R.id.alarm_num_rl);
        mMarketValueEt = (EditText) findViewById(R.id.market_value_et);
        mMarketValueRl = (RelativeLayout) findViewById(R.id.market_value_rl);
        mOriginalPriceValueEt = (EditText) findViewById(R.id.original_price_value_et);
        mOriginalPriceRl = (RelativeLayout) findViewById(R.id.original_price_rl);
        mActiveTypeValueEt = (EditText) findViewById(R.id.active_type_value_et);
        mActionTypeRl = (RelativeLayout) findViewById(R.id.action_type_rl);
        mLimitPurchaseQuantityEt = (EditText) findViewById(R.id.limit_purchase_quantity_et);
        mLimitPurchaseQuantityRl = (RelativeLayout) findViewById(R.id.limit_purchase_quantity_rl);
        mSellingPriceValueEt = (EditText) findViewById(R.id.selling_price_value_et);
        mSellingPriceRl = (RelativeLayout) findViewById(R.id.selling_price_rl);
        mCommissionSettingValueEt = (EditText) findViewById(R.id.commission_setting_value_et);
        mCommissionSettingRl = (RelativeLayout) findViewById(R.id.commission_setting_rl);
        mAddProductMainPictureLl = (LinearLayout) findViewById(R.id.add_product_main_picture_ll);
        mAddProductOtherPictureLl1 = (LinearLayout) findViewById(R.id.add_product_other_picture_ll1);
        mAddProductOtherPictureLl2 = (LinearLayout) findViewById(R.id.add_product_other_picture_ll2);
        mAddProductOtherPictureLl3 = (LinearLayout) findViewById(R.id.add_product_other_picture_ll3);
        mProposalTv = (TextView) findViewById(R.id.proposal_tv);
        mShopNoticeEt = (EditText) findViewById(R.id.shop_notice_et);
        mShopNoticeRl = (RelativeLayout) findViewById(R.id.shop_notice_rl);
        mAddContentMainPictureLl = (LinearLayout) findViewById(R.id.add_content_main_picture_ll);
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

        getData();

    }

    private void getData() {


    }

    @Override
    public void showQueryShopBrandSuccessMsg(String s, QueryShopBrandBean queryShopBrandBean) {
        /**
         * 根据店铺的id进行查找店铺的品牌
         */
    }

    @Override
    public void showQueryAllMarksSuccessMsg(String s, QueryAllMarksBean queryAllMarksBean) {
        /**
         * 门店运营-商品管理-查询所有标签
         */
    }

    @Override
    public void showQueryAllClassfySuccessMsg(String s, AllClassfyBean allClassfyBean) {
        /**
         * 查询店铺下所有分类
         */
    }

    @Override
    public void showQueryAllTerraceSuccessMsg(String s, QueryAllTerraceBean queryAllTerraceBean) {
        /**
         * 查询所有平台分类
         */

    }

    /**
     * 查詢商品详情
     *
     * @param s
     * @param goodsDetailBean
     */
    @Override
    public void showQueryAllGoodsDetailSuccessMsg(String s, GoodsDetailBean goodsDetailBean) {
        Toasty.success(this, s).show();
        mProductNameEt.setText(goodsDetailBean.getData().getGoodsName()+"");
        mCommodityClassificationBusinessValueEt.setText(goodsDetailBean.getData().getStoreId()+"");
        mCommodityClassificationPlatformValueEt.setText(goodsDetailBean.getData().getClassId()+"");
        mCommodityBrandValueEt.setText(goodsDetailBean.getData().getBrandName()+"");
        mBarCodeValueTv.setText(goodsDetailBean.getData().getGoodsBarcodeList().get(0).getGoodsBarcode()+"");
        mMeasureUnitValueEt.setText(goodsDetailBean.getData().getGoodsUnit()+"");
        mCommodityTagValueEt.setText(goodsDetailBean.getData().getGoodsTagList().get(0).getName()+"");
        mCommoditySpecificationsValueEt.setText(goodsDetailBean.getData().getGoodsSpecification()+"");
        mCountryOfOriginValueEt.setText(goodsDetailBean.getData().getGoodsPlace()+"");
        Toasty.info(this,goodsDetailBean.getData().getGoodsWeight()+"").show();
        mWeightValueEt.setText(goodsDetailBean.getData().getGoodsWeight()+"");
        mWarehouseAddressValueEt.setText(goodsDetailBean.getData().getAreaInfo()+"");

        if (goodsDetailBean.getData().getIsForeign() == 0) {
            mConfirmRb.setChecked(true);
            mConfirmRb.toggle();
        } else {
            mCancelRb.setChecked(false);
        }
        if (goodsDetailBean.getData().getGoodsVat() == 0) {
            mConfirmInvoiceRb.setChecked(true);
        } else {
            mCancelInvoiceRb.setChecked(false);
        }
        mInventoryQuantityValueEt.setText(goodsDetailBean.getData().getGoodsStorage()+"");
        mAlarmNumValueEt.setText(goodsDetailBean.getData().getGoodsStorageAlarm()+"");
        mMarketValueEt.setText(goodsDetailBean.getData().getGoodsMarketPrice()+"");
        mOriginalPriceValueEt.setText(goodsDetailBean.getData().getGoodsPrice()+"");
        if (goodsDetailBean.getData().getActivityType() == 0) {
            mActiveTypeValueEt.setText("无活动");
        } else if (goodsDetailBean.getData().getActivityType() == 1) {
            mActiveTypeValueEt.setText("促销");
        } else if (goodsDetailBean.getData().getActivityType() == 2) {
            mActiveTypeValueEt.setText("秒杀");
        } else {
            mActiveTypeValueEt.setText("折扣");
        }
        mLimitPurchaseQuantityEt.setText(goodsDetailBean.getData().getDiscount()+"");
        mSellingPriceValueEt.setText(goodsDetailBean.getData().getGoodsLimitNum()+"");
        mCommissionSettingValueEt.setText(goodsDetailBean.getData().getGoodsPromotionPrice()+"");
    }

    @Override
    public void showErrorMsg(String s) {
        Toasty.error(this, s).show();
    }
}
